/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.business.commons.utils;

import java.security.MessageDigest;

/**
 *
 * @author user
 */
public class MD5Utils {

    /*
    public static void main(String []args){
        String p = MD5Utils.md5Password("1488781348899A5D883919E15326712396784300321348D113509121611475F930");
        System.out.println(p);
    }
     */
    /**
     * md5加密方法
     *
     * @param password
     * @return
     */
    public static String md5Password(String password) {

        try {
            // 得到一个信息摘要器  
            MessageDigest digest = MessageDigest.getInstance("md5");
            byte[] result = digest.digest(password.getBytes());
            StringBuffer buffer = new StringBuffer();
            // 把没一个byte 做一个与运算 0xff;  
            for (byte b : result) {
                // 与运算  
                int number = b & 0xff;// 加盐  
                String str = Integer.toHexString(number);
                if (str.length() == 1) {
                    buffer.append("0");
                }
                buffer.append(str);
            }

            // 标准的md5加密后的结果  
            return buffer.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

    }

    public static void main(String[] args) {
        String[] codes = "a,b,c,d".split(",");
        for (String code : codes) {
            switch (code) {
                case "a":
                    System.out.println("a");
                    break;
                case "b":
                    System.out.println("b");
                    break;
                case "c":
                    System.out.println("c");
                    break;
                case "d":
                    System.out.println("d");
                    break;
            }
        }
    }
}
